from flask import g

def login_required(func):
    """
    用户必须登录装饰器
    使用: 放在method_decorators中
    """
    def wrapper(*args, **kwargs):
        if g.user_id is not None:
            return func(*args, **kwargs)
        else:
            return {'message': 'Invalid token'}, 401

    return wrapper